<template>
  <div id="target">
    <div class="attentionTitle">
      <div>{{$t('userAdmin.attention.title')}}</div>
    </div>
    <el-table
      v-if="noResponse"
      v-loading="loading"
      style="width: 100%;height: 419px;margin: 10px auto;z-index: 1">
    </el-table>
    <el-empty v-if="isEmpty" :image-size="200"></el-empty>
    <div class="box" v-if="!isEmpty" v-for="(item, index) in contentData" :key="index">
      <div class="attention-left">
        <div class="attention-left-left">
          <router-link target="_blank" :to="{path:'/userHomePage', query:{ userId : item.userId }}">
            <img :src=item.interestedHeadPhotoPath alt="" width="55px" class="head-pho">
          </router-link>
        </div>
        <div class="attention-left-right">
          <div class="title">
            <div class="userName">{{item.interestedNicknametem==""?item.interestedId:item.interestedNickname}}</div>
            <div class="gender">
              <i class="iconfont icon-nan" style="color: rgb(0, 125, 228); font-weight:bolder"></i>
            </div>
          </div>
          <div class="sign">
            {{item.interestedSign==""? $t('userAdmin.attention.decInfo'):item.interestedSign}}
          </div>
        </div>
      </div>
      <div class="attention-middle"><i class="iconfont icon-guanzhushijian"></i>
        {{item.interestDate}}
      </div>
      <div class="attention-right">
        <router-link target="_blank":to="{path:'/userHomePage', query:{ userId : item.interestedId }}">
          <div class="goUserHome"><i class="iconfont icon-shouye"></i>{{$t('userAdmin.attention.button01')}}</div>
        </router-link>
        <a href="javascript:;" @click="cancelAttention(item.interestedId)">
          <div class="cancelAttention">
            <i class="iconfont icon-31guanzhudianpu"></i>
            {{$t('userAdmin.attention.button02')}}
          </div></a>
      </div>
    </div>
    <el-pagination
      v-if="!isEmpty && !noResponse"
      background
      layout="prev, pager, next"
      :total=pageTotal
      @current-change="handleCurrentChange(currentPage)"
      :current-page.sync = currentPage
      class="page">
    </el-pagination>
  </div>
</template>

<script>
    export default {
        name: "UserAdminMyAttention",
        data(){
            return{
                imageUrl: [],
                loading:"true",
                isEmpty:false,
                noResponse: true,
                baseURL:'http://localhost:8081/userAdmin/interest/',
                baseURL2:'http://localhost:8081/userAdmin/getPages/interest',
                baseURL3:'http://localhost:8081/userHomePage/cancelConcerned/',
                contentData:'',
                pageTotal:0,
                currentPage:1  // 当前页
            }
        },
        mounted() {
            this.$emit("component","myAttention")
            this.getAttentionInfo()
            this.getPages()
        },
        methods:{
            getAttentionInfo(){
                this.axios.post(this.baseURL + this.currentPage).then(res => {
                    this.noResponse = false
                    if (res.data != "empty") {
                        this.contentData = res.data
                    }else {
                        this.isEmpty = true
                    }
                }).catch(
                    exception=>{
                        console.log(exception)
                    }
                )
            },
            getPages(){
                this.axios.post(this.baseURL2).then(res => {
                    this.pageTotal = res.data * 10
                }).catch(
                    exception=>{
                        console.log(exception)
                    }
                )
            },
            cancelAttention(attentionID){
                this.$confirm(this.$t('userAdmin.attention.confirm.info'), {
                    confirmButtonText: this.$t('userAdmin.attention.confirm.confirm'),
                    cancelButtonText: this.$t('userAdmin.attention.confirm.cancel'),
                    showClose: false,
                    type: 'warning'
                }).then(() => {
                    this.axios.post(this.baseURL3+attentionID).then(res=>{
                        if (res.data == true){
                            this.successOpt(this.$t('userAdmin.attention.confirm.successTip'))
                            this.getAttentionInfo()
                        } else if(res.data==false) {
                            this.failOpt(this.$t('userAdmin.attention.confirm.faiTip'))
                        } else{
                            this.warningOpt(this.$t('userAdmin.attention.confirm.serviceUnusual'))
                        }
                    }).catch(
                        exception=>{
                            console.log(exception)
                        }
                    )
                }).catch(() => {
                    console.log(this.$t('userAdmin.attention.confirm.cancelTip'))
                });
            },
            handleCurrentChange(currentPage){
                this.axios.post(this.baseURL+currentPage).then(res=>{
                    this.noResponse=false
                    if (res.data != "empty"){
                        // this.getHeadPhoto(res.data)
                        this.contentData = res.data
                        let target = document.getElementById("target").offsetTop
                        window.scrollTo({
                            top:target,
                            behavior: "smooth"
                        });
                    }
                }).catch(
                    exception=>{
                        console.log(exception)
                    }
                )
            },
            successOpt(message) {
                this.$notify({
                    title: this.$t('notify.success'),
                    message: message,
                    type: 'success'
                })
            },
            failOpt(message) {
                this.$notify.error({
                    title: this.$t('notify.error'),
                    message: message
                });
            },
            warningOpt(message) {
                this.$notify.warning({
                    title: '提示',
                    message: message
                });
            }

        }
    }
</script>

<style scoped>
  .box{
    margin: 10px auto;
    height: 90px;
    width: 100%;
    background-color: rgba(255, 255, 255, 0.9);
    border-radius: 3px;
    border: rgb(228, 228, 228) 1px solid;
    transition: 0.2s;
    letter-spacing:1px;
    position: relative;
  }
  .attentionTitle{
    width: 100%;
    background-color: white;
    margin-bottom: 10px;
    border-radius: 3px;
  }
  .attentionTitle div{
    height: 50px;
    line-height: 50px;
    font-size: 18px;
    color: #414141;
    margin-left: 20px;
  }
  .box:hover{
    box-shadow: 0 0 5px rgb(196, 196, 196);
    transform:translateY(-1px);
  }
  .attention-left{
    float: left;
    height: 90px;
    max-width: 500px;
  }
  .attention-left-left{
    float: left;
    width: 60px;
    height: 90px;
    margin-left: 20px;
  }
  .head-pho{
    border-radius: 50%;
    margin-top: 17px;
  }
  .attention-left-right{
    float: left;
    max-width: 370px;
    height: 90px;
  }
  .title{
    height: 45px;
    max-width:370px;
  }
  .userName{
    float: left;
    height: 45px;
    max-width:340px;
    line-height: 60px;
    font-size: 18px;
    color: rgb(59, 59, 59);

    display: -webkit-box;
    overflow:hidden;
    text-overflow: ellipsis;
    -webkit-box-orient:vertical;
    -webkit-line-clamp:1;
  }
  .gender{
    float: left;
    width: 30px;
    height: 30px;
    line-height: 30px;
    margin-top: 10px;
  }
  .gender i{
    text-align: left;

  }
  .sign{
    height: 45px;
    line-height: 35px;
    font-size: 13px;
    color: rgb(95, 95, 95);

    display: -webkit-box;
    overflow:hidden;
    text-overflow: ellipsis;
    -webkit-box-orient:vertical;
    -webkit-line-clamp:1;
  }
  .attention-middle{
    float: left;
    height: 90px;
    width: 180px;
    line-height: 125px;
    font-size: 12px;
    color: rgb(148, 148, 148);
    margin-left: 20px;
  }
  .attention-right{
    float: left;
    height: 90px;
    width: 100px;

    position: absolute;
    top: 0px;
    right: 20px;
  }
  .goUserHome, .cancelAttention{
    height: 32px;
    line-height: 32px;
    width: 100px;
    text-align: center;
    color: rgb(116, 116, 116);
    font-size: 12px;
    border-radius: 3px;
    margin-top: 7px;
    border: 1px solid rgb(227, 227, 227);
  }
  .goUserHome:hover, .cancelAttention:hover{
    background-color: rgb(109, 109, 109);
    color: rgb(245, 245, 245);
  }
  .page{
    margin: 10px auto;
    margin-left: -10px;
  }
</style>
